package com.longma.server.security;

import cn.hutool.core.bean.BeanUtil;
import com.longma.server.entity.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author HIBO
 * @Description 定义满足Spring Security规则的用户实体类
 */
public class JwtUserDetails extends SysUser implements UserDetails {

    public JwtUserDetails(SysUser loginUser){
        BeanUtil.copyProperties(loginUser, this);
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return new ArrayList<>();
    }

    @Override
    public String getUsername() {
        return getLoginName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
